package net.zisen.cloud.order.ctrl;

import net.zisen.cloud.base.msg.ResultMsg;
import net.zisen.cloud.order.client.OrderServiceClient;
import net.zisen.cloud.order.model.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tim/278002989@qq.com
 * @Classname OrderConsumerCtrl
 * @Description TODO
 * @Date 2019-05-17 19:25
 */
@RestController
public class OrderConsumerCtrl {

    @Autowired
    private OrderServiceClient orderClient;


    @PostMapping("order")
    public ResultMsg addOrder(@RequestParam Long uid, @RequestParam Long goodsId, @RequestParam Integer quality) {
        return orderClient.addOrder(uid, goodsId, quality);
    }


    @GetMapping("pay/order")
    public ResultMsg payOrder(@RequestParam String orderNum) {
        return orderClient.payOrder(orderNum);
    }


    @PostMapping("add/and/pay/order")
    public ResultMsg<Order> addAndPayOrder(@RequestParam Long uid, @RequestParam Long goodsId, @RequestParam Integer quality) throws Exception {
        ResultMsg<Order> resultMsg = this.orderClient.addOrder(uid, goodsId, quality);
        if (resultMsg != null && resultMsg.isSuccess()) {
            return this.orderClient.payOrder(resultMsg.getData().getNum());
        }
        return resultMsg;
    }
}
